/**
 * 
 */
package ar.utn.frgp.banco.interceptor;

import ar.utn.frgp.banco.dto.UserDTO;
import ar.utn.frgp.banco.front.constants.Constantes;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * @author PUSDERKIS
 *
 */
public class AutenticationInterceptor implements Interceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4140807992531312970L;

	/**
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#destroy()
	 */
	public void destroy() {}

	/**
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#init()
	 */
	public void init() {}

	/**
	 * @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
	 */
	public String intercept(ActionInvocation invocation) throws Exception {
		
		
		UserDTO dto = null;
		if (invocation.getInvocationContext().getSession().get(Constantes.USER_LOGGED_BEAN) != null){
			dto = (UserDTO)invocation.getInvocationContext().getSession().get(Constantes.USER_LOGGED_BEAN);
		}
		
		if (dto == null || !dto.isLogOk()){
			return Action.LOGIN;
		}
		
		return invocation.invoke();
	}

}
